package com.soushangxing.comfyuibackendv2.repository


import com.aliyun.oss.OSS
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Repository
import java.io.ByteArrayInputStream


@Repository
class AliyunRepository: DatabaseBaseRepository() {
    @Autowired
    private lateinit var oss:OSS

    @Value("\${aliyun.oss.bucket-name}")
    lateinit var bucketName: String // bucket名

    /**
     * 上传文件
     */
    override fun putObject(objectName: String, data: ByteArray){
        this.oss.putObject(bucketName, objectName, ByteArrayInputStream(data))
    }

    /**
     * 删除文件
     */
    override fun deleteObject(objectName: String){
        this.oss.deleteObject(bucketName, objectName)
    }

    /**
     * 判断文件是否存在
     */
    override fun isExist(objectName: String): Boolean {
        return oss.doesObjectExist(bucketName, objectName)
    }
}
